using UnityEngine;
using System.Collections;
using UnityEditor;

public class OrthographicCameraMovement : MonoBehaviour 
{
	//Use this boolean to ensure the mouse is over the correct GUI in order to manipulate the camera direction
	public bool isOnGUI;
	
	private Vector3 directionalV;
	private Vector3 wantedPosition;
	
	private float ySpeed = 15.0F;
	private float xSpeed = 15.0F;
	private float mouseSpeed = 10.0F;
	// Use this for initialization
	void Start () 
	{
		directionalV = (new Vector3 (0,0,0) );
		wantedPosition = this.gameObject.transform.position;
	}
	
	void Update ()
	{
		if ( Input.GetKey( KeyCode.W ) )
		{
			iTween.Stop ( this.gameObject );
			directionalV = (new Vector3 ( 0,ySpeed, 0 ) );
			Vector3 newPos = this.gameObject.transform.position  + directionalV;
			iTween.MoveUpdate ( this.gameObject, newPos, 2.0F );
		}
		if ( Input.GetKeyUp ( KeyCode.W ) )
		{
			Vector3 newPos = this.gameObject.transform.position  + directionalV;
			iTween.MoveTo ( this.gameObject, iTween.Hash ( "position", newPos, "time", 1.0F, "easeType",iTween.EaseType.easeOutCubic ) );
		}
	
		if ( Input.GetKey( KeyCode.A ) )
		{
			iTween.Stop ( this.gameObject );
			directionalV = (new Vector3 ( -xSpeed,0,0  ) );
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveUpdate ( this.gameObject, newPos, 2.0F );
		}
		if ( Input.GetKeyUp ( KeyCode.A ) )
		{
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveTo ( this.gameObject, iTween.Hash ( "position", newPos, "time", 1.0F, "easeType",iTween.EaseType.easeOutCubic ) );
		}
		
		if ( Input.GetKey( KeyCode.S ) )
		{
			iTween.Stop ( this.gameObject );
			directionalV = (new Vector3 ( 0,-ySpeed,0 ) );
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveUpdate ( this.gameObject, newPos, 2.0F );
		}
		if ( Input.GetKeyUp ( KeyCode.S ) )
		{
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveTo ( this.gameObject, iTween.Hash ( "position", newPos, "time", 1.0F, "easeType",iTween.EaseType.easeOutCubic ) );
		}
		
		if ( Input.GetKey ( KeyCode.D ) )
		{
			iTween.Stop ( this.gameObject );
			directionalV = (new Vector3 ( xSpeed, 0,0 ) );
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveUpdate ( this.gameObject, newPos, 2.0F );
		}
		if ( Input.GetKeyUp ( KeyCode.D ) )
		{
			Vector3 newPos = this.gameObject.transform.position + directionalV;
			iTween.MoveTo ( this.gameObject, iTween.Hash ( "position", newPos, "time", 1.0F, "easeType",iTween.EaseType.easeOutCubic ) );
		}
		
	}
	
	// Update is called once per frame
	void LateUpdate () 
	{
		//Zoom in and out.
		//Use your scrollWheel.
		//this.transform.position = this.transform.position + (new Vector3 ( 0,0,  Input.GetAxis ( "Mouse ScrollWheel" ) * 5.0F ) );
		this.gameObject.GetComponent<Camera>().orthographicSize += Input.GetAxis ( "Mouse ScrollWheel" );
		
		if ( Input.GetMouseButton (2) )
		{
			iTween.Stop ( this.gameObject );
			float y = Input.GetAxis ("Mouse Y") ;
			float x = Input.GetAxis ("Mouse X");
			
			Vector3 v = new Vector3 ( x,y, 0);
			wantedPosition = transform.position + v.normalized * mouseSpeed;
			
			iTween.MoveUpdate ( this.gameObject, wantedPosition, 2.0F );			
		}
		if ( Input.GetMouseButtonUp (2) )
		{
			iTween.MoveTo ( this.gameObject, iTween.Hash("position",wantedPosition, "time",1.0F,  "easeType", iTween.EaseType.easeOutCubic) );
		}
	}
	
	
	void OnGUI ()
	{
		
	}
	
	
}
